package ma.fsm.arda.command.strategy;
import ma.fsm.arda.command.Command;
public class Coward implements AutoStrategy {
	private Command command ;
	private boolean started = true;
	
	
	
	public Coward(Command command){
	    	this.command= command;
	}
	
	public Coward(){
		
	}
	@Override

	public void execute() {
		if (!command.isAuto()) {
			command.setAuto(true);
			
		    while (started) {
			    System.out.println("loop..");

			    Short sensorValueA = command.sensorA();
			    Short sensorValueB = command.sensorB();

			    System.out.println(sensorValueA);
			    System.out.println(sensorValueB);

			    if ((sensorValueA > 200) && (sensorValueB < 200)) {
				command.goRight();
			    }
			    if ((sensorValueB > 200) && (sensorValueA < 200)) {
				command.goLeft();
			    }

			    if ((sensorValueA < 200) && (sensorValueB < 200)) {
				command.goForward();
			    }

			    if ((sensorValueA > 200) && (sensorValueB > 200)) {
					if (sensorValueA > sensorValueB) {
						command.spinRight();
					}
					if (sensorValueA < sensorValueB) {
						command.spinLeft();
					}

			    }

		   }

	       command.stop();
	       command.setAuto(false);
	       System.out.println("loop out");
	}
		
	}

	@Override
	public void stop() {
		System.out.println("STOPED");
		started = false;
		
	}
	public Command getCommand() {
		return command;
	}

	public void setCommand(Command command) {
		this.command = command;
	}

}
